package com.jk.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jk.dao.TbClassMapper;
import com.jk.dto.TbClass;
import com.jk.interfaces.TbClassServiceApi;
import com.jk.pojo.PagedResponse;
import com.jk.service.TbClassService;
import com.jk.utils.PaginationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.UUID;

/**
 * @author yzf
 * @version 1.0
 * @description: TODO
 * @date 2024/12/12 15:37
 */
@Service
public class TbClassServiceImpl implements TbClassService {
    @Autowired
    private TbClassMapper tbClassMapper;

    @Override
    public PagedResponse<TbClass> findTbClassList(TbClass tbClass, Integer pageNum, Integer pageSize) {
        Page<TbClass> page = new Page<>(pageNum, pageSize);
        IPage<TbClass> ipage = tbClassMapper.findTbClassList(page, tbClass);
        return PaginationUtil.getPagedResponse(ipage.getRecords(),pageNum,pageSize,ipage.getTotal());
    }

    @Override
    public void delTbClassById(Integer id) {
        tbClassMapper.deleteById(id);
        //删除中间表
        tbClassMapper.delClassAndStudentById(id);
    }

    @Override
    public void addTbClass(TbClass tbClass) {
        String uuid = UUID.randomUUID().toString();
        tbClass.setClassWord(uuid);
        tbClass.setPeopleNum(0);
        tbClassMapper.insert(tbClass);
    }

    @Override
    public TbClass getTbClassById(Integer id) {
        return tbClassMapper.selectById(id);
    }

    @Override
    public void upTbClass(TbClass tbClass) {
        tbClassMapper.updateById(tbClass);
    }
}
